from core.basehandler import BaseHandler
from core.room import Room
from core.support import set_cutscene
from core.action import Action

class Sword(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)
        self.swordE_applied = False
        self.swordF_applied = False
        self.desc = ''
        self.activation_counter = 0
        self.add_action(SwordA)
        self.add_action(SwordB)
        self.add_action(SwordC)
        self.add_action(SwordD)
        self.add_action(SwordE)
        self.add_action(SwordF)
    
    def get_description(self):
        if not(self.swordE_applied and self.swordF_applied):
            self.desc = '''
            You came into a room with giant stone door sealed. 
            But there is an altar and 6 different colored swords placed in middle of room.
            You are guessing-Maybe I should find the right COLOR combination of TWO swords to put into the sockets and open the door?
            Hint: On the stone you find two circles. The inner circle is orange and the outer is purple. You have only three chances to pick the correct sword
            '''
        else:
            self.desc = "The stone door slides aside."
        return self.desc
    
    def get_image(self):
        return "Sword_room.JPG"
    
    # report whether this room is illuminated
    # which can happen if the room or player has a lit lamp
class SwordHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Sword

# define actions for this room

class OrderSword(Action):
    def __init__(self):
        Action.__init__(self, "order_sword")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Open Door"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        if not(room.swordE_applied and room.swordF_applied):
            set_cutscene("The door can't open")
        else:
            room.add_action(SwordToSoldier)
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

class SwordA(Action):
    def __init__(self):
        Action.__init__(self, "swordA")    # do basic initialization for every action
        self.deathflag = False
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Activate Sword A"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        room.activation_counter += 1
        if not(room.swordE_applied and room.swordF_applied):
            if room.activation_counter >= 3:
                self.deathflag = True
                set_cutscene("You triggered a trap!")
            else:
                set_cutscene("Nothing happened")
            
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    def get_destination(self):
        if self.deathflag:
            return "death"
        else:
            return "swords"

class SwordB(Action):
    def __init__(self):
        Action.__init__(self, "swordB")    # do basic initialization for every action
        self.deathflag=False
        
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Activate Sword B"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        room.activation_counter += 1
        if not(room.swordE_applied and room.swordF_applied):
            if room.activation_counter >= 3:
                self.deathflag = True
                set_cutscene("You triggered a trap!")
            else:
                set_cutscene("Nothing happened")
            
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    def get_destination(self):
        if self.deathflag:
            return "death"
        else:
            return "swords"
    
class SwordC(Action):
    def __init__(self):
        Action.__init__(self, "swordC")    # do basic initialization for every action
        self.deathflag=False
        
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Activate Sword C"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        room.activation_counter += 1
        if not(room.swordE_applied and room.swordF_applied):
            if room.activation_counter >= 3:
                self.deathflag = True
                set_cutscene("You triggered a trap!")
            else:
                set_cutscene("Nothing happened")
    
    def get_destination(self):
        if self.deathflag:
            return "death"
        else:
            return "swords"
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
class SwordD(Action):
    def __init__(self):
        Action.__init__(self, "swordD")    # do basic initialization for every action
        self.deathflag=False
        
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Activate Sword D"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        room.activation_counter += 1
        if not(room.swordE_applied and room.swordF_applied):
            if room.activation_counter >= 3:
                self.deathflag = True
                set_cutscene("You triggered a trap!")
            else:
                set_cutscene("Nothing happened")
    
    def get_destination(self):
        if self.deathflag:
            return "death"
        else:
            return "swords"
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
class SwordE(Action):
    def __init__(self):
        Action.__init__(self, "swordE")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Activate Sword E"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        room.swordE_Applied=True
        if room.swordF_applied:
            set_cutscene("The door is open now")
            room.add_action(SwordToSoldier)
        else:
            set_cutscene("You heard a clang from the door")
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
class SwordF(Action):
    def __init__(self):
        Action.__init__(self, "swordF")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Activate Sword F"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        room.swordF_Applied=True
        if room.swordE_Applied:
            set_cutscene("The door is open now")
            room.add_action(SwordToSoldier)
        else:
            set_cutscene("You heard a clang from the door")
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"


class SwordToSoldier(Action):
    def __init__(self):
        Action.__init__(self, "sword_to_soldier")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use the door and proceed"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'soldier'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"